#ifndef __GLES2DefaultHardwareBufferManager_H__
#define __GLES2DefaultHardwareBufferManager_H__

#include "HardwareBufferManager.h"
#include "HardwareVertexBuffer.h"
#include "HardwareIndexBuffer.h"

namespace PVM
{
	class GLES2DefaultHardwareVertexBuffer : public HardwareVertexBuffer
	{
	protected:
		unsigned char* mpData;
		void* lockImpl(size_t offset, size_t length, LockOptions options);
		void unlockImpl(void);
		
	public:
		GLES2DefaultHardwareVertexBuffer(size_t vertexSize, size_t numVertices,
										 HardwareBuffer::Usage usage);
		GLES2DefaultHardwareVertexBuffer(HardwareBufferManagerBase* mgr, size_t vertexSize, size_t numVertices,
										 HardwareBuffer::Usage usage);
		virtual ~GLES2DefaultHardwareVertexBuffer();
		
		void readData(size_t offset, size_t length, void* pDest);
		void writeData(size_t offset, size_t length, const void* pSource,
					   bool discardWholeBuffer = false);
		void* lock(size_t offset, size_t length, LockOptions options);
		void unlock(void);
		
		void* getDataPtr(size_t offset) const {return (void*)(mpData + offset);}
	};
	
	class GLES2DefaultHardwareIndexBuffer : public HardwareIndexBuffer
	{
	protected:
		unsigned char* mpData;
		void* lockImpl(size_t offset, size_t length, LockOptions options);
		void unlockImpl(void);
		
	public:
		GLES2DefaultHardwareIndexBuffer(IndexType idxType, size_t numIndexes, HardwareBuffer::Usage usage);
		virtual ~GLES2DefaultHardwareIndexBuffer();
		
		void readData(size_t offset, size_t length, void* pDest);
		void writeData(size_t offset, size_t length, const void* pSource,
					   bool discardWholeBuffer = false);
		void* lock(size_t offset, size_t length, LockOptions options);
		void unlock(void);
		
		void* getDataPtr(size_t offset) const {return (void*)(mpData + offset);}
	};
	
	class GLES2DefaultHardwareBufferManagerBase : public HardwareBufferManagerBase
	{
	public:
		GLES2DefaultHardwareBufferManagerBase();
		virtual ~GLES2DefaultHardwareBufferManagerBase();
		HardwareVertexBufferSharedPtr
		createVertexBuffer(size_t vertexSize, size_t numVerts,
						   HardwareBuffer::Usage usage, bool useShadowBuffer = false);
		HardwareIndexBufferSharedPtr
		createIndexBuffer(HardwareIndexBuffer::IndexType itype, size_t numIndexes,
						  HardwareBuffer::Usage usage, bool useShadowBuffer = false);
		
		RenderToVertexBufferSharedPtr createRenderToVertexBuffer(void);
	};
	
	class GLES2DefaultHardwareBufferManager : public HardwareBufferManager
	{
	public:
		GLES2DefaultHardwareBufferManager()
		: HardwareBufferManager(new GLES2DefaultHardwareBufferManagerBase())
		{
		}
		
		~GLES2DefaultHardwareBufferManager()
		{
			delete mImpl;
		}
	};
}

#endif
